'use strict';

/**
 * @param {Egg.Application} app - egg application
 */
module.exports = app => {
  const { router, controller,io } = app;

  router.get('/admin',controller.admin.home.index)

  router.get('/admin/manager/delete/:id',controller.admin.manager.delete);
  router.get('/admin/manager/edit/:id',controller.admin.manager.edit);
  router.get('/admin/manager',controller.admin.manager.index);
  router.get('/admin/manager/create',controller.admin.manager.create);
  router.post('/admin/manager',controller.admin.manager.save);
  router.post('/admin/manager/:id',controller.admin.manager.update);
  
  router.get('/admin/feedback',controller.admin.feedback.index);
  router.get('/admin/feedback/check/:id', controller.admin.feedback.check);
  router.get('/admin/feedback/delete/:id',controller.admin.feedback.delete);


  //仅用于临时增加管理员（避免管理员为0时出现无法访问后台的情况）
  // router.get('/admin/reg_temp',controller.admin.manager.create);

  router.get('/admin/login',controller.admin.home.login);
  router.post('/admin/loginevent',controller.admin.home.loginevent);
  router.get('/admin/logout', controller.admin.home.logout);

  router.get('/admin/user/delete/:id',controller.admin.user.delete);
  router.get('/admin/user/edit/:id',controller.admin.user.edit);
  router.get('/admin/user',controller.admin.user.index);
  router.get('/admin/user/create',controller.admin.user.create);
  router.post('/admin/user',controller.admin.user.save);
  router.post('/admin/user/:id',controller.admin.user.update);

  router.get('/admin/gift/delete/:id',controller.admin.gift.delete);
  router.get('/admin/gift/edit/:id',controller.admin.gift.edit);
  router.get('/admin/gift/create',controller.admin.gift.create);
  router.post('/admin/gift',controller.admin.gift.save);
  router.get('/admin/gift', controller.admin.gift.index);
  router.post('/admin/gift/:id',controller.admin.gift.update);

  router.post('/admin/upload', controller.admin.common.upload);

  router.get('/admin/order/delete/:id',controller.admin.order.delete);
  router.get('/admin/order', controller.admin.order.index);

  router.get('/admin/live', controller.admin.live.index);

  router.get('/admin/post', controller.admin.post.index);
  router.get('/admin/post/delete/:id',controller.admin.post.delete);

  router.get('/admin/station', controller.admin.rescueStation.index);
  router.get('/admin/station/check/:id', controller.admin.rescueStation.check);

  router.get('/admin/live/look/:id', controller.admin.live.look);
  router.get('/admin/live/gift/:id', controller.admin.live.gift);
  router.get('/admin/live/comment/:id', controller.admin.live.comment);
  router.get('/admin/live/close/:id', controller.admin.live.close);
  router.get('/admin/live/delete/:id',controller.admin.live.delete);

  // 用户注册
  router.post('/api/reg', controller.api.user.reg);
  // 用户登录
  router.post('/api/login', controller.api.user.login);
  // 退出登录
  router.post('/api/logout', controller.api.user.logout);
  // 获取当前用户信息
  router.get('/api/user/info', controller.api.user.info);
  // 获取目标用户信息
  router.get('/api/user/getinfo/:id', controller.api.user.getinfo);
  // 修改用户信息
  router.post('/api/user/update/:id',controller.api.user.update);
  // 用户绑定邮箱
  router.post('/api/user/bindEmail/:id',controller.api.user.bindEmail);
  //查看关注页面
  router.get('/api/follows/:page/:user_id',controller.api.follows.followerPage);
  //获取关注列表
  router.get('/api/follows/:user_id',controller.api.follows.followerList);
  //查看粉丝页面
  router.get('/api/fans/:page/:follower_id',controller.api.follows.fanPage);
  //获取粉丝列表
  router.get('/api/fans/:user_id',controller.api.follows.fanList);
  //修改关注状态
  router.post('/api/follows/doFollow',controller.api.follows.doFollow);
  //关注计数
  router.get('/api/countFollower/:user_id',controller.api.follows.countFollower);
  //粉丝计数
  router.get('/api/countFan/:user_id',controller.api.follows.countFan);
  // 创建直播间
  router.post('/api/live/create', controller.api.live.save);
  // 修改直播间状态
  router.post('/api/live/changestatus', controller.api.live.changeStatus);
  // 直播间列表
  router.get('/api/live/list/:page',controller.api.live.list)
  // 查看直播间
  router.get('/api/live/read/:id', controller.api.live.read);
  //用户举报
  router.post('/api/user/feedback/:id',controller.api.user.feedback);
  // 微信支付
  router.post('/api/gift/wxpay', controller.api.gift.wxpay);
  // 微信支付回调
  router.post('/api/gift/notify', app.middleware.tenpay('pay', app), controller.api.gift.notify);

  // // 获取指定用户信息
  // router.get('/api/user/getcounts/:user_id', controller.api.user.getcounts);
  // 用户发布帖子
  router.post('/api/post/sendpost/:id', controller.api.post.sendPost);
  // 用户修改密码
  router.post('/api/user/updatepassword/:id', controller.api.user.updatepassword);
  // 按照帖子类型查看帖子
  router.get('/api/post/typePost/:type/:page', controller.api.post.typePost);
  //添加浏览记录
  router.post('/api/post/addhistory/:id/:post_id', controller.api.post.addHistory);
  //查找帖子
  router.get('/api/post/searchpost/:title', controller.api.post.searchPost);
  //模糊查找救助站
  //router.get('/api/rescue_station/searchStation/:name',controller.api.rescueStation.searchStation);
  //根据救助站id查找其帖子
  router.get('/api/rescue_station/byStationIdPost/:id',controller.api.rescueStation.byStationIdPost);
  //根据救助站id查找动物列表
  router.get('/api/rescue_station/byStationIdAnimal/:id',controller.api.rescueStation.byStationIdAnimal);
  //根据动物id查找相关的帖子
  router.get('/api/rescue_station/byAnimalIdPost/:id',controller.api.rescueStation.byAnimalIdPost);
  //发送帖子图片
  router.post('/api/post/sendpostimagelist',controller.api.post.sendPostImageList);
  //添加图片列表
  router.post('/api/post/sendlist',controller.api.post.sendList);

  //模糊查找救助站
  router.get('/api/rescue_station/searchStation/:name',controller.api.rescueStation.searchStation);
  //首页查看所有救助站
  router.get('/api/rescue_station/lookStation/:page',controller.api.rescueStation.lookStation);
  //根据id查找具体的救助站信息
  router.get('/api/rescue_station/byIdSearchStation/:id',controller.api.rescueStation.byIdSearchStation);
  //申请修改机构信息
  router.post('/api/rescue_station/updateStation/:id', controller.api.rescueStation.updateStation);
  //认证为机构
  router.post('/api/rescue_station/idenitfy/:id', controller.api.rescueStation.idenitfy);

  //根据id查找一个帖子的具体信息
  router.get('/api/post/lookpost/:id', controller.api.post.lookPost);

  // 礼物列表
  router.get('/api/gift/list',controller.api.gift.list)
  // 上传图片
  router.post('/api/upload', controller.api.common.upload);
 

  io.of('/').route('joinLive',io.controller.nsp.joinLive)
  io.of('/').route('leaveLive',io.controller.nsp.leaveLive)
  io.of('/').route('comment',io.controller.nsp.comment)
  io.of('/').route('gift',io.controller.nsp.gift)

};
